/**
 * 获取 json 对象 的所有值
 * @param key
 * @param json
 * @returns {string}
 */
function getKey(key, json) {
    var typeStr = Object.prototype.toString.call(json);
    if (typeStr == '[object Array]') {
        return `[${key}]`
    }
    return `.${key}`

}
function testData({json, itemVal, keyVal, res = {}, fatherKey = "", ObjArr=[]}) {
    if (ObjArr.includes(json)) {
        return res;
    }
    ObjArr.push(json)
    for (var key in json) {
        var item = json[key];
        if (!item) {
            continue;
        }
        var typeStr = Object.prototype.toString.call(item);

        let strKey = fatherKey + getKey(key, json);
        if (typeStr == '[object String]' || typeStr == '[object Number]') {
            // 条件内容 ----------------start----------------------
            if (item == itemVal || key == keyVal || fatherKey.endsWith(`.${keyVal}`)) {
                console.log(strKey, item);
            }
            // 条件内容 ----------------end----------------------
        } else if (typeStr == '[object Array]' || typeStr == '[object Object]') {
            testData({
                json: item,
                itemVal,
                keyVal,
                res,
                fatherKey: strKey,
                ObjArr
            });
        }
    }
    return res;
}
testData({
    json: {
        myOne: {
            myTwo: 123
        },
        M1231: {
            sdf: [
                123,
                34
            ]
        }
    },
    itemVal:123,
    keyVal: 'sdf'
})